home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Audio / AC3 / AC3Dec / ac3_internal.h next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  9.2 KB  |  345 lines

  1. /* 
  2.  *    ac3_internal.h
  3.  *
  4.  *    Copyright (C) Aaron Holtzman - May 1999
  5.  *
  6.  *  This file is part of ac3dec, a free Dolby AC-3 stream decoder.
  7.  *    
  8.  *  ac3dec is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  ac3dec is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24. #ifndef __GNUC__
  25. #define inline 
  26. #endif
  27.  
  28. /* Exponent strategy constants */
  29. #define EXP_REUSE (0)
  30. #define EXP_D15   (1)
  31. #define EXP_D25   (2)
  32. #define EXP_D45   (3)
  33.  
  34. /* Delta bit allocation constants */
  35. #define DELTA_BIT_REUSE (0)
  36. #define DELTA_BIT_NEW (1)
  37. #define DELTA_BIT_NONE (2)
  38. #define DELTA_BIT_RESERVED (3)
  39.  
  40. /* samples work structure */
  41. typedef float stream_samples_t[6][256];
  42.  
  43. /* global config structure */
  44. extern ac3_config_t ac3_config;
  45. /* global error flag */
  46. extern uint_32 error_flag;
  47.  
  48. /* Everything you wanted to know about band structure */
  49. /*
  50.  * The entire frequency domain is represented by 256 real
  51.  * floating point fourier coefficients. Only the lower 253
  52.  * coefficients are actually utilized however. We use arrays
  53.  * of 256 to be efficient in some cases.
  54.  *
  55.  * The 5 full bandwidth channels (fbw) can have their higher
  56.  * frequencies coupled together. These coupled channels then
  57.  * share their high frequency components.
  58.  *
  59.  * This coupling band is broken up into 18 sub-bands starting
  60.  * at mantissa number 37. Each sub-band is 12 bins wide.
  61.  *
  62.  * There are 50 bit allocation sub-bands which cover the entire
  63.  * frequency range. The sub-bands are of non-uniform width, and
  64.  * approximate a 1/6 octave scale.
  65.  */
  66.  
  67. /* The following structures are filled in by their corresponding parse_*
  68.  * functions. See http://www.atsc.org/Standards/A52/a_52.pdf for
  69.  * full details on each field. Indented fields are used to denote
  70.  * conditional fields.
  71.  */
  72.  
  73. typedef struct syncinfo_s
  74. {
  75.     uint_32    magic;
  76.     /* Sync word == 0x0B77 */
  77.     /* uint_16   syncword; */
  78.     /* crc for the first 5/8 of the sync block */
  79.     /* uint_16   crc1; */
  80.     /* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */
  81.     uint_16        fscod;    
  82.     /* Frame size code */
  83.     uint_16        frmsizecod;
  84.  
  85.     /* Information not in the AC-3 bitstream, but derived */
  86.     /* Frame size in 16 bit words */
  87.     uint_16 frame_size;
  88.     /* Bit rate in kilobits */
  89.     uint_16 bit_rate;
  90.     /* sampling rate in hertz */
  91.     uint_32 sampling_rate;
  92.  
  93. } syncinfo_t;
  94.  
  95. typedef struct bsi_s
  96. {
  97.     uint_32    magic;
  98.     /* Bit stream identification == 0x8 */
  99.     uint_16 bsid;    
  100.     /* Bit stream mode */
  101.     uint_16 bsmod;
  102.     /* Audio coding mode */
  103.     uint_16 acmod;
  104.     /* If we're using the centre channel then */
  105.         /* centre mix level */
  106.         uint_16 cmixlev;
  107.     /* If we're using the surround channel then */
  108.         /* surround mix level */
  109.         uint_16 surmixlev;
  110.     /* If we're in 2/0 mode then */
  111.         /* Dolby surround mix level - NOT USED - */
  112.         uint_16 dsurmod;
  113.     /* Low frequency effects on */
  114.     uint_16 lfeon;
  115.     /* Dialogue Normalization level */
  116.     uint_16 dialnorm;
  117.     /* Compression exists */
  118.     uint_16 compre;
  119.         /* Compression level */
  120.         uint_16 compr;
  121.     /* Language code exists */
  122.     uint_16 langcode;
  123.         /* Language code */
  124.         uint_16 langcod;
  125.     /* Audio production info exists*/
  126.     uint_16 audprodie;
  127.         uint_16 mixlevel;
  128.         uint_16 roomtyp;
  129.     /* If we're in dual mono mode (acmod == 0) then extra stuff */
  130.         uint_16 dialnorm2;
  131.         uint_16 compr2e;
  132.             uint_16 compr2;
  133.         uint_16 langcod2e;
  134.             uint_16 langcod2;
  135.         uint_16 audprodi2e;
  136.             uint_16 mixlevel2;
  137.             uint_16 roomtyp2;
  138.     /* Copyright bit */
  139.     uint_16 copyrightb;
  140.     /* Original bit */
  141.     uint_16 origbs;
  142.     /* Timecode 1 exists */
  143.     uint_16 timecod1e;
  144.         /* Timecode 1 */
  145.         uint_16 timecod1;
  146.     /* Timecode 2 exists */
  147.     uint_16 timecod2e;
  148.         /* Timecode 2 */
  149.         uint_16 timecod2;
  150.     /* Additional bit stream info exists */
  151.     uint_16 addbsie;
  152.         /* Additional bit stream length - 1 (in bytes) */
  153.         uint_16 addbsil;
  154.         /* Additional bit stream information (max 64 bytes) */
  155.         uint_8    addbsi[64];
  156.  
  157.     /* Information not in the AC-3 bitstream, but derived */
  158.     /* Number of channels (excluding LFE)
  159.      * Derived from acmod */
  160.     uint_16 nfchans;
  161. } bsi_t;
  162.  
  163.  
  164. /* more pain */
  165. typedef struct audblk_s
  166. {
  167.     uint_32    magic1;
  168.     /* block switch bit indexed by channel num */
  169.     uint_16 blksw[5];
  170.     /* dither enable bit indexed by channel num */
  171.     uint_16 dithflag[5];
  172.     /* dynamic range gain exists */
  173.     uint_16 dynrnge;
  174.         /* dynamic range gain */
  175.         uint_16 dynrng;
  176.     /* if acmod==0 then */
  177.     /* dynamic range 2 gain exists */
  178.     uint_16 dynrng2e;
  179.         /* dynamic range 2 gain */
  180.         uint_16 dynrng2;
  181.     /* coupling strategy exists */
  182.     uint_16 cplstre;
  183.         /* coupling in use */
  184.         uint_16 cplinu;
  185.             /* channel coupled */
  186.             uint_16 chincpl[5];
  187.             /* if acmod==2 then */
  188.                 /* Phase flags in use */
  189.                 uint_16 phsflginu;
  190.             /* coupling begin frequency code */
  191.             uint_16 cplbegf;
  192.             /* coupling end frequency code */
  193.             uint_16 cplendf;
  194.             /* coupling band structure bits */
  195.             uint_16 cplbndstrc[18];
  196.             /* Do coupling co-ords exist for this channel? */
  197.             uint_16 cplcoe[5];
  198.             /* Master coupling co-ordinate */
  199.             uint_16 mstrcplco[5];
  200.             /* Per coupling band coupling co-ordinates */
  201.             uint_16 cplcoexp[5][18];
  202.             uint_16 cplcomant[5][18];
  203.             /* Phase flags for dual mono */
  204.             uint_16 phsflg[18];
  205.     /* Is there a rematrixing strategy */
  206.     uint_16 rematstr;
  207.         /* Rematrixing bits */
  208.         uint_16 rematflg[4];
  209.     /* Coupling exponent strategy */
  210.     uint_16 cplexpstr;
  211.     /* Exponent strategy for full bandwidth channels */
  212.     uint_16 chexpstr[5];
  213.     /* Exponent strategy for lfe channel */
  214.     uint_16 lfeexpstr;
  215.     /* Channel bandwidth for independent channels */
  216.     uint_16 chbwcod[5];
  217.         /* The absolute coupling exponent */
  218.         uint_16 cplabsexp;
  219.         /* Coupling channel exponents (D15 mode gives 18 * 12 /3  encoded exponents */
  220.         uint_16 cplexps[18 * 12 / 3];
  221.     /* Sanity checking constant */
  222.     uint_32    magic2;
  223.     /* fbw channel exponents */
  224.     uint_16 exps[5][252 / 3];
  225.     /* channel gain range */
  226.     uint_16 gainrng[5];
  227.     /* low frequency exponents */
  228.     uint_16 lfeexps[3];
  229.  
  230.     /* Bit allocation info */
  231.     uint_16 baie;
  232.         /* Slow decay code */
  233.         uint_16 sdcycod;
  234.         /* Fast decay code */
  235.         uint_16 fdcycod;
  236.         /* Slow gain code */
  237.         uint_16 sgaincod;
  238.         /* dB per bit code */
  239.         uint_16 dbpbcod;
  240.         /* masking floor code */
  241.         uint_16 floorcod;
  242.  
  243.     /* SNR offset info */
  244.     uint_16 snroffste;
  245.         /* coarse SNR offset */
  246.         uint_16 csnroffst;
  247.         /* coupling fine SNR offset */
  248.         uint_16 cplfsnroffst;
  249.         /* coupling fast gain code */
  250.         uint_16 cplfgaincod;
  251.         /* fbw fine SNR offset */
  252.         uint_16 fsnroffst[5];
  253.         /* fbw fast gain code */
  254.         uint_16 fgaincod[5];
  255.         /* lfe fine SNR offset */
  256.         uint_16 lfefsnroffst;
  257.         /* lfe fast gain code */
  258.         uint_16 lfefgaincod;
  259.     
  260.     /* Coupling leak info */
  261.     uint_16 cplleake;
  262.         /* coupling fast leak initialization */
  263.         uint_16 cplfleak;
  264.         /* coupling slow leak initialization */
  265.         uint_16 cplsleak;
  266.     
  267.     /* delta bit allocation info */
  268.     uint_16 deltbaie;
  269.         /* coupling delta bit allocation exists */
  270.         uint_16 cpldeltbae;
  271.         /* fbw delta bit allocation exists */
  272.         uint_16 deltbae[5];
  273.         /* number of cpl delta bit segments */
  274.         uint_16 cpldeltnseg;
  275.             /* coupling delta bit allocation offset */
  276.             uint_16 cpldeltoffst[8];
  277.             /* coupling delta bit allocation length */
  278.             uint_16 cpldeltlen[8];
  279.             /* coupling delta bit allocation length */
  280.             uint_16 cpldeltba[8];
  281.         /* number of delta bit segments */
  282.         uint_16 deltnseg[5];
  283.             /* fbw delta bit allocation offset */
  284.             uint_16 deltoffst[5][8];
  285.             /* fbw delta bit allocation length */
  286.             uint_16 deltlen[5][8];
  287.             /* fbw delta bit allocation length */
  288.             uint_16 deltba[5][8];
  289.  
  290.     /* skip length exists */
  291.     uint_16 skiple;
  292.         /* skip length */
  293.         uint_16 skipl;
  294.  
  295.     //Removed Feb 2000 -ah
  296.     /* channel mantissas */
  297.     //uint_16 chmant[5][256];
  298.  
  299.     /* coupling mantissas */
  300.     uint_16 cplmant[256];
  301.  
  302.     //Removed Feb 2000 -ah
  303.     /* coupling mantissas */
  304.     //uint_16 lfemant[7];
  305.  
  306.  
  307.     /*  -- Information not in the bitstream, but derived thereof  -- */
  308.  
  309.     /* Number of coupling sub-bands */
  310.     uint_16 ncplsubnd;
  311.  
  312.     /* Number of combined coupling sub-bands
  313.      * Derived from ncplsubnd and cplbndstrc */
  314.     uint_16 ncplbnd;
  315.  
  316.     /* Number of exponent groups by channel
  317.      * Derived from strmant, endmant */
  318.     uint_16 nchgrps[5];
  319.  
  320.     /* Number of coupling exponent groups
  321.      * Derived from cplbegf, cplendf, cplexpstr */
  322.     uint_16 ncplgrps;
  323.             
  324.     /* End mantissa numbers of fbw channels */
  325.     uint_16 endmant[5];
  326.  
  327.     /* Start and end mantissa numbers for the coupling channel */
  328.     uint_16 cplstrtmant;
  329.     uint_16 cplendmant;
  330.  
  331.     /* Decoded exponent info */
  332.     uint_16 fbw_exp[5][256];
  333.     uint_16 cpl_exp[256];
  334.     uint_16 lfe_exp[7];
  335.  
  336.     /* Bit allocation pointer results */
  337.     uint_16 fbw_bap[5][256];
  338.     uint_16 cpl_bap[256];
  339.     uint_16 lfe_bap[7];
  340.     
  341.     uint_32    magic3;
  342. } audblk_t;
  343.  
  344.  
  345.